<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui">

<ui:composition template="/WEB-INF/templates/interna.xhtml">
	<ui:define name="nav">
		<h:form id="menu">
			<p:menu id="menuItens" styleClass="menu">
				<p:menuitem value="Cadastro" url="/admin/categoria/cadastro"/>
				<p:menuitem value="Atualiza&ccedil;&atilde;o" url="/admin/categoria/atualizacao"/>
				<p:menuitem value="Ativar categoria" url="/admin/categoria/ativacao"/>
			</p:menu>
		</h:form>
	</ui:define>

	<ui:define name="centro">

		<h2 class="titulo-admin">Atualiza&ccedil;&atilde;o de categorias</h2>

		<p:separator id="separator" styleClass="separador" />

		<h:form id="formCategoria">

			<p:messages id="messages" 
			    showDetail="true" 
			    autoUpdate="true"
				showSummary="false" />

			<div id="box-cat-esq">

				<h:panelGrid columns="2" cellspacing="2">			
				  					
				   <p:selectOneMenu id="list"
				   value="#{categoriaManagedBean.categoriaSelecionada}" 
				   effect="fade" 
				   converter="categoriaConverter">
				   
				        <f:selectItem itemLabel="-- Selecione --" itemValue="" />
				   		<f:selectItems value="#{categoriaManagedBean.categorias}"
							var="categoria" 
							itemLabel="#{categoria.nome}"
							itemValue="#{categoria}"/>	
							
						<p:ajax update="nome list2 list3" 
						process="@this, list" 
						listener="#{categoriaManagedBean.limparNivelDoisTres()}"/>					
				   </p:selectOneMenu>		
				   
				   <p:commandButton value="Carregar n&iacute;vel 2"
						actionListener="#{categoriaManagedBean.carregarNivel2()}"
						update="list2" 
						process="@this, list" />
				   				
				</h:panelGrid>
				
				<br/><br/>		
				<h:outputText value="Editar categoria selecionada:" />		
				<h:panelGrid columns="2" cellspacing="2">					
							  
				   <h:outputText value="Nome" />			  
				   <p:inputText value="#{categoriaManagedBean.categoriaSelecionada.nome}"
						id="nome" 
						required="true"
						requiredMessage="Nome deve ser informado">
						<f:validateLength for="nome" minimum="3" />
					</p:inputText>
					
					<h:outputText value="Ativo " />  
        			<p:selectOneMenu id="ativo" value="#{categoriaManagedBean.categoriaSelecionada.ativo}">
        			    <f:selectItem itemLabel="Sim" itemValue="true"/> 
        				<f:selectItem itemLabel="N&atilde;o" itemValue="false" />           			           			     			            			
        			</p:selectOneMenu>			
				
				</h:panelGrid>
				
				<h:panelGrid columns="2" cellspacing="2">				
					
					<p:commandButton value="Atualizar"
						actionListener="#{categoriaManagedBean.atualizarNivel1()}"
						update="nome ativo list list2 list3" 
						process="@this, nome, ativo" />				
				
				</h:panelGrid>

			</div>

			<div id="box-cat-dir">
			
				<h:panelGrid columns="1" cellspacing="2">			
				  					
				   <p:selectOneMenu id="list3"
				   value="#{categoriaManagedBean.subParenteSelecionada}" 
				   effect="fade" 
				   converter="categoriaConverter">
				   
				        <f:selectItem itemLabel="-- Selecione --" itemValue="" />
				   		<f:selectItems value="#{categoriaManagedBean.subsParentes}"
							var="subParente" 
							itemLabel="#{subParente.nome}"
							itemValue="#{subParente}" />
						
						<p:ajax update="snome" 
						process="@this, list3" 
						listener="#{categoriaManagedBean.limparNivelDoisTres()}"/>							
				   </p:selectOneMenu>				  
				   				
				</h:panelGrid>
				
				<br/><br/>	
				<h:outputText value="Editar categoria selecionada:" />		
				<h:panelGrid columns="2" cellspacing="2">					
							  
				   <h:outputText value="Nome" />	
				   <p:inputText value="#{categoriaManagedBean.subParenteSelecionada.nome}"
						id="snome" 
						required="true"
						requiredMessage="Nome deve ser informado">
						<f:validateLength for="snome" minimum="3" />
					</p:inputText>
					
					<h:outputText value="Ativo " />  
        			<p:selectOneMenu id="sativo" value="#{categoriaManagedBean.subParenteSelecionada.ativo}">
        			    <f:selectItem itemLabel="Sim" itemValue="true"/> 
        				<f:selectItem itemLabel="N&atilde;o" itemValue="false" />           			           			     			            			
        			</p:selectOneMenu>	
				
				</h:panelGrid>
				
				<h:panelGrid columns="2" cellspacing="2">				
					
					<p:commandButton value="Atualizar"
						actionListener="#{categoriaManagedBean.atualizarNivel3}"
						update="snome sativo list3" 
						process="@this, snome sativo" />										
				
				</h:panelGrid>		
				
			</div>

			<div id="box-cat-centro">
				
				<h:panelGrid columns="2" cellspacing="2">			
				  					
				   <p:selectOneMenu id="list2"
				   value="#{categoriaManagedBean.catParenteSelecionada}" 
				   effect="fade" 
				   converter="categoriaConverter">
				   
				        <f:selectItem itemLabel="-- Selecione --" itemValue="" />
				   		<f:selectItems value="#{categoriaManagedBean.catsParentes}"
							var="catParente" 
							itemLabel="#{catParente.nome}"
							itemValue="#{catParente}" />
						
						<p:ajax update="cnome list3" 
						process="@this, list2" 
						listener="#{categoriaManagedBean.limparNivelTres()}"/>							
				   </p:selectOneMenu>		
				   
				   <p:commandButton value="Carregar n&iacute;vel 3"
						actionListener="#{categoriaManagedBean.carregarNivel3()}"
						update="list3" 
						process="@this, list2" />
				   				
				</h:panelGrid>
				
				<br/><br/>	
				<h:outputText value="Editar categoria selecionada:" />		
				<h:panelGrid columns="2" cellspacing="2">						  
				   	
				   <h:outputText value="Nome" />
				   <p:inputText value="#{categoriaManagedBean.catParenteSelecionada.nome}"
						id="cnome" 
						required="true"
						requiredMessage="Nome deve ser informado">
						<f:validateLength for="cnome" minimum="3" />
					</p:inputText>
					
					<h:outputText value="Ativo " />  
        			<p:selectOneMenu id="cativo" value="#{categoriaManagedBean.catParenteSelecionada.ativo}">
        			    <f:selectItem itemLabel="Sim" itemValue="true"/> 
        				<f:selectItem itemLabel="N&atilde;o" itemValue="false" />           			           			     			            			
        			</p:selectOneMenu>	
				
				</h:panelGrid>
				
				<h:panelGrid columns="1" cellspacing="2">				
					
					<p:commandButton value="Atualizar"
						actionListener="#{categoriaManagedBean.atualizarNivel2()}"
						update="cnome cativo list2" 
						process="@this, cnome cativo" />					
				
				</h:panelGrid>		
				
			</div>
		</h:form>
	</ui:define>
</ui:composition>
</html>